package com.ymatou.iapi.optrade.parameter.enums;

import java.util.HashMap;
import java.util.Map;

/**
 */
public enum BargainGroupStatusEnum {
	//砍价团(-3 组团失败, -2 参团失败, -1 开团失败, 0 默认砍价团, 1 开团成功, 2 参团成功, 3 组团成功)

	GROUP_INIT(0, "砍价团初始"),
	OPEN_GROUP_SUCCESS(1, "开团成功"),
	JOIN_GROUP_SUCCESS(2, "参团成功"),
	FINISH_GROUP_SUCCESS(3, "组团成功"),
	OPEN_GROUP_FAIL(-1, "开团失败"),
	JOIN_GROUP_FAIL(-2, "参团失败"),
	FINISH_GROUP_FAIL(-3, "组团失败");

	private static final Map<Integer, BargainGroupStatusEnum> maps = new HashMap<>();

	static {
		for (BargainGroupStatusEnum bargainGroupStatus : BargainGroupStatusEnum
				.values()) {
			maps.put(bargainGroupStatus.getCode(), bargainGroupStatus);
		}
	}

	private int code;
	private String message;

	private BargainGroupStatusEnum(int code, String message) {
		this.code = code;
		this.message = message;
	}

	public static BargainGroupStatusEnum findByCode(Integer code) {
		BargainGroupStatusEnum bargainGroupStatus = maps.get(code);
		if (bargainGroupStatus == null) {
			throw new IllegalArgumentException(
					"BargainGroupStatus not found,code:" + code);
		}
		return bargainGroupStatus;
	}

	/**
	 * 是否是失败状态
	 *
	 * @param code
	 * @return
	 */
	public static boolean isFail(Integer code) {
		if (code != null
				&& (code.equals(OPEN_GROUP_FAIL.getCode())
						|| code.equals(JOIN_GROUP_FAIL.getCode()) || code
							.equals(FINISH_GROUP_FAIL.getCode()))) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 是否是完结状态
	 *
	 * @param code
	 * @return
	 */
	public static boolean isFinishStatus(Integer code) {
		if (code != null
				&& (code.equals(FINISH_GROUP_SUCCESS.getCode())
						|| code.equals(OPEN_GROUP_FAIL.getCode())
						|| code.equals(JOIN_GROUP_FAIL.getCode()) || code
							.equals(FINISH_GROUP_FAIL.getCode()))) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 是否需要返还库存(已经扣过了)
	 *
	 * @param code
	 * @return
	 */
	public static boolean needReturnStock(Integer code) {
		if (code == null) {
			return false;
		}
		if (code.equals(OPEN_GROUP_SUCCESS.getCode())
				|| code.equals(JOIN_GROUP_SUCCESS.getCode())
				|| code.equals(FINISH_GROUP_SUCCESS.getCode())
				|| code.equals(FINISH_GROUP_FAIL.getCode())) {
			return true;
		}
		return false;
	}

	public int getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}
}
